package com.mo.axion.common.enums;

import com.mo.axion.common.dto.model.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Mo
 * @createTime 2024/2/2 11:41
 * @descripiton 发送渠道类型枚举
 */
@Getter
@ToString
@AllArgsConstructor
public enum ChannelType implements PowerfulEnum{

    /**
     * IM(站内消息) TODO
     */
    IM(10, "IM(站内信 即时通讯)", ImContentModel.class, "im", null, null),

    /**
     * push（通知栏） TODO
     */
    PUSH(20, "PUSH(通知栏)", PushContentModel.class, "push", null, null),

    /**
     * sms短信
     */
    SMS(30, "sms(短信)", SmsContentModel .class, "sms", null, null),


    /**
     * email 邮箱
     */
    EMAIL(40, "email(邮件)", EmailContentModel.class, "email", null, null),
    /**
     * 微信服务号
     */
    OFFICIAL_ACCOUNT(50, "officialAccounts(服务号)", OfficialAccountsContentModel.class, "official_accounts", "official_account_", null),
    ;

    /**
     * 编码值
     */
    private final Integer code;

    /**
     * 描述
     */
    private final String description;

    /**
     * 内容模型Class
     */
    private final Class<? extends ContentModel> contentModelClass;

    /**
     * 英文标识
     */
    private final String codeEn;

    /**
     * accessToken prefix
     */
    private final String accessTokenPrefix;

    /**
     * accessToken expire
     * 单位秒
     */
    private final Long accessTokenExpire;

    /**
     * 通过code获取class
     *
     * @param code
     * @return
     */
    public static Class<? extends ContentModel> getChannelModelClassByCode(Integer code) {
        return Arrays.stream(values()).filter(channelType -> Objects.equals(code, channelType.getCode()))
                .map(ChannelType::getContentModelClass)
                .findFirst().orElse(null);
    }
}
